package com.bite.javaSEreview.j20240712;

import java.util.Arrays;

/**
 * @author kiku-wa
 */
public class Test {
    public static void main(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};

        for(int[] temp: array){
            for(int x : temp){
                System.out.print(x + " ");
            }
            System.out.println();
        }

        System.out.println(Arrays.deepToString(array));
        System.out.println(Arrays.toString(array));

        int[][] array2 = new int[][]{{1,2,3},{4,5,6}};

        int[][] array3 = new int[2][3];
    }
    public static void main8(String[] args) {
        int[] array1 = {1,2,3,4,5,6,7,18,9};
        int[] array2 = {1,2,3,4,5,6,7,18,9,20};

        boolean flg =Arrays.equals(array1,array2);
        System.out.println(flg);


        int[] array3 = new int[10];
        Arrays.fill(array3,3,5,-1);//[3,5)
        System.out.println(Arrays.toString(array3));
    }
    public static void main7(String[] args) {
        int[] arr = {1,4,2,6,2,8,0,6};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.binarySearch(arr,6));
    }
    public static void main6(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        /**
         * 参数1：是要拷贝的数组
         * 参数2：是要拷贝的长度
         */
        int[] copy1 = Arrays.copyOf(array,2*array.length);
        int[] copy2 = Arrays.copyOfRange(array,0,15);//[2,5)
        System.out.println(Arrays.toString(copy1));
        System.out.println(Arrays.toString(copy2));
    }

    public static int[] test() {
        int[] ret = {1,2,3,4};
        return ret;
    }
    public static void main5(String[] args) {
        int[] tmp = test();
        System.out.println(Arrays.toString(tmp));
    }
    public static void func1(int[] array) {
        array = new int[]{1,2,3};
    }
    public static void func2(int [] array) {
        array[0] = 199;
    }
    public static void main4(String[] args) {
        int[] array = {10,20,30};
        //func1(array);
        func2(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main3(String[] args) {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;
        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array1.length; i++) {
            System.out.print(array1[i]+" ");
        }
        System.out.println();
        System.out.println("===============");
        for (int i = 0; i < array2.length; i++) {
            System.out.print(array2[i]+" ");
        }
    }
    public static void main2(String[] args) {
        int[] array2 = null;
        //报错，空指针异常
        System.out.println(array2.length);

    }
    public static void main1(String[] args) {
        int[] array = {1, 2, 3, 4, 5};
        int[] array2 = new int[]{1,2,3,4};
        int a = 10;
        int[] array3 = new int[a];

        //int arr[] = new int[]{1,2,3};
        int[] array4;
        array4 = new int[]{1,2,4};

//        int[] array5;
//        array5 = {1,2,3,4,5};//报错
        boolean[] flg = new boolean[5];

        System.out.println(array);
        for(int x: array2){
            System.out.print(x + " ");
        }
        System.out.println();
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
}
